<template>
  <div class="cityCheckResult">
    <el-form
      class="basicInfoForm"
      :inline="true"
      label-position="left"
      :model="numData"
      label-width="80px"
    >
      <div class="maintitle">项目基本情况</div>
      <div class="basicInfo">
        <div>
          <span class="tit">项目名称：</span>
          <span>{{numData.projectName}}</span>
        </div>
      </div>
      <div class="formcontent labelNormal">
        <el-form-item label="申报单位">
          <el-input readonly v-model="numData.declareUnit"></el-input>
        </el-form-item>
        <el-form-item label="作业单位">
          <el-input readonly v-model="numData.operationUnit"></el-input>
        </el-form-item>
      </div>
      <div class="basicInfo">
        <div>
          <span class="tit">红线面积：</span>
          <span>{{numData.redLineArea}}公顷</span>
        </div>
      </div>
      <div class="formcontent labelNormal">
        <el-form-item label="实施规模">
          <el-input readonly v-model="numData.implementScale">
            <i slot="suffix">公顷</i>
          </el-input>
        </el-form-item>
        <el-form-item label="整理规模">
          <el-input readonly v-model="numData.arrangeScale">
            <i slot="suffix">公顷</i>
          </el-input>
        </el-form-item>
        <el-form-item label="开发规模">
          <el-input readonly v-model="numData.developScale">
            <i slot="suffix">公顷</i>
          </el-input>
        </el-form-item>
      </div>

      <div class="maintitle">分等因素属性</div>
      <div class="formcontent labelNormal">
        <div>
          <el-form-item label="有效图层厚度-增加值" label-width="150px">
            <el-input readonly v-model="numData.layerThickness"></el-input>
          </el-form-item>
          <el-form-item label="土壤有机质含量-增加值" label-width="160px">
            <el-input readonly v-model="numData.mechanismContent"></el-input>
          </el-form-item>
          <el-form-item label="土壤酸碱度-增加值" label-width="150px">
            <el-input readonly v-model="numData.soilPh"></el-input>
          </el-form-item>
          <el-form-item label="表层土壤质地-增加值" label-width="150px">
            <el-input readonly v-model="numData.soilTexture"></el-input>
          </el-form-item>
          <el-form-item label="海拔高度-增加值" label-width="150px">
            <el-input readonly v-model="numData.altitudeHeight"></el-input>
          </el-form-item>
          <el-form-item label="地形坡度-增加值" label-width="160px">
            <el-input readonly v-model="numData.terrainSlope"></el-input>
          </el-form-item>
          <el-form-item label="梯地状况-增加值" label-width="150px">
            <el-input readonly v-model="numData.ladderStatus"></el-input>
          </el-form-item>
        </div>
      </div>

      <div class="maintitle">提质改造前</div>
      <div class="formcontent labelNormal">
        <div>
          <el-form-item label="水田面积" label-width="80px">
            <el-input readonly v-model="numData.beforeWaterArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等别" label-width="80px">
            <el-input readonly v-model="numData.beforeWaterAreaAvg">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="旱地面积" label-width="80px">
            <el-input readonly v-model="numData.beforeDryArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等别" label-width="80px">
            <el-input readonly v-model="numData.beforeDryAreaAvg">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="耕地面积" label-width="80px">
            <el-input readonly v-model="numData.beforePlowArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等别" label-width="80px">
            <el-input readonly v-model="numData.beforePlowAreaAvg">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
      </div>

      <div class="maintitle">提质改造后</div>
      <div class="formcontent labelNormal">
        <div>
          <el-form-item label="水田面积" label-width="80px">
            <el-input readonly v-model="numData.afterWaterArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等别" label-width="80px">
            <el-input readonly v-model="numData.afterWaterAreaAvg">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="旱地面积" label-width="80px">
            <el-input readonly v-model="numData.afterDryArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等别" label-width="80px">
            <el-input readonly v-model="numData.afterDryAreaAvg">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="耕地面积" label-width="80px">
            <el-input readonly v-model="numData.afterPlowArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等别" label-width="80px">
            <el-input readonly v-model="numData.afterPlowAreaAvg">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
      </div>

      <div class="maintitle">旱改水面积及等别</div>
      <div class="formcontent labelNormal">
        <div>
          <el-form-item label="旱改水面积" label-width="98px">
            <el-input readonly v-model="numData.droughtChangeArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等别" label-width="80px">
            <el-input readonly v-model="numData.droughtChangeAreaAvg">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
      </div>

      <div class="maintitle">整治前耕地质量等别</div>
      <div class="formcontent labelNormal">
        <div>
          <el-form-item label="水田" label-width="50px">
            <el-input readonly v-model="numData.remediationBeforeWater">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="旱地" label-width="50px">
            <el-input readonly v-model="numData.remediationBeforeDry">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="耕地" label-width="50px">
            <el-input readonly v-model="numData.remediationBeforePlow">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
      </div>

      <div class="maintitle">整治后耕地质量等别</div>
      <div class="formcontent labelNormal">
        <div>
          <el-form-item label="水田" label-width="50px">
            <el-input readonly v-model="numData.remediationAfterWater">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="旱地" label-width="50px">
            <el-input readonly v-model="numData.remediationAfterDry">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="耕地" label-width="50px">
            <el-input readonly v-model="numData.remediationAfterPlow">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
        </div>
      </div>

      <div class="maintitle">新增耕地质量等别及面积</div>
      <div class="formcontent equalArea labelNormal">
        <div>
          <el-form-item label="水田面积" label-width="100px">
            <el-input readonly v-model="numData.newWaterArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等级" label-width="100px">
            <el-input readonly v-model="numData.newWaterAreaAvg"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="旱地面积" label-width="100px">
            <el-input readonly v-model="numData.newDryArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等级" label-width="100px">
            <el-input readonly v-model="numData.newDryAreaAvg"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="耕地面积" label-width="100px">
            <el-input readonly v-model="numData.newPlowArea">
              <i slot="suffix">公顷</i>
            </el-input>
          </el-form-item>
          <el-form-item label="平均等级" label-width="100px">
            <el-input readonly v-model="numData.newPlowAreaAvg"></el-input>
          </el-form-item>
        </div>
        <div>
          <el-form-item label="新增产能" label-width="100px">
            <el-input readonly v-model="numData.newProductionCapacity">
              <i slot="suffix">公斤</i>
            </el-input>
          </el-form-item>
          <el-form-item label="提升产能" label-width="100px">
            <el-input readonly v-model="numData.upgradeProductionCapacity">
              <i slot="suffix">公斤</i>
            </el-input>
          </el-form-item>
          <el-form-item label="合计" label-width="100px">
            <el-input readonly v-model="numData.totalProductionCapacity">
              <i slot="suffix">公斤</i>
            </el-input>
          </el-form-item>
        </div>
      </div>

      <div class="maintitle">审查意见</div>
      <div class="formAllRow">
        <div>
          <el-form-item label="经办人审查意见" label-width="150px">
            <el-input readonly v-model="form1.opinion" style="width:774px;" type="textarea" rows="8"></el-input>
          </el-form-item>
        </div>
      </div>

      <div class="formcontent">
        <div>
          <el-form-item label="签字" label-width="60px">
            <img style="width: 100px;" :src="`${baseUrl}${form1.signature}`" alt />
          </el-form-item>
          <el-form-item label="审查日期" label-width="110px">
            <el-date-picker
              style="width:160px"
              readonly
              v-model="form1.createTime"
              type="date"
              placeholder="审查日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="审查意见">
            <el-select disabled v-model="form1.status" style="width:160px" placeholder="请选择">
              <el-option label="同意" :value="0"></el-option>
              <el-option label="拒绝" :value="1"></el-option>
            </el-select>
          </el-form-item>
        </div>
      </div>
      <div class="formAllRow">
        <div>
          <el-form-item label="复核人审查意见" label-width="150px">
            <el-input :readonly="disabled" v-model="form.opinion" style="width:774px;" type="textarea" rows="8"></el-input>
          </el-form-item>
        </div>
      </div>

      <div class="formcontent">
        <div>
          <el-form-item label="签字" label-width="60px">
            <img style="width: 100px;" :src="`${baseUrl}${form.signature || signature}`" alt />
          </el-form-item>
          <el-form-item label="审查日期" label-width="110px">
            <el-date-picker
             :readonly="disabled"
              style="width:160px"
              v-model="form.createTime"
              type="date"
              placeholder="审查日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item label="审查意见" label-width="110px">
            <el-select :disabled="disabled" v-model="form.status" style="width:160px" placeholder="请选择">
              <el-option label="同意" :value="0"></el-option>
              <el-option label="拒绝" :value="1"></el-option>
            </el-select>
          </el-form-item>
        </div>
      </div>

      <div style="margin-top:60px;">
        <el-form-item>
          <el-button v-if="!disabled" @click="addAdvice" type="primary">提交</el-button>
          <el-button v-if="!disabled">取消</el-button>
          <el-button v-if="disabled" @click="back">返回</el-button>
        </el-form-item>
      </div>
    </el-form>
  </div>
</template>

<script>
import config from "@/config/index.js";
import moment from "moment";
import {
  getInvAndCon,
  getAdvice,
  addAdvice,
  getSignature,
  addResult
} from "@/api/completionAcceptance/cityCheckResult.js";
export default {
  name: "checkProcess",
  components: {
    process
  },
  data() {
    return {
      numData: {
        flag: 1,
        projectId: localStorage.getItem("projectId")
      },
      form1: {
        signature: "",
        groupId: 19,
        projectId: localStorage.getItem("projectId"),
        type: 0,
        status: 0,
        opinion: "",
        createTime: ""
      },
      form: {
        signature: "",
        groupId: 19,
        projectId: localStorage.getItem("projectId"),
        type: 1,
        status: 0,
        opinion: "",
        createTime: ""
      },
      baseUrl: config.baseUrlImg,
      signature: "",
      disabled: true,
      projectId: localStorage.getItem("projectId") || ""
    };
  },

  created() {
    if (this.$route.name === localStorage.getItem("key")) {
      this.disabled = false;
    }
    this.getInvAndCon();
    this.getAdvice();
    this.getAdvice1();
    this.getSignature();
    this.getTime()
  },
  methods: {
    back(){
      this.$router.push("/projectManagement/projectImplementation/dealwith")
    },
    getTime(){
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        if (month < 10) {
            month = "0" + month;
        }
        if (day < 10) {
            day = "0" + day;
        }
        var trueTime = year + "-" + month + "-" + day
        
        this.form.createTime = trueTime
    },
    getInvAndCon() {
      //获取基本数据信息
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      getInvAndCon({ projectId: this.projectId })
        .then(res => {
          loading.close();
          this.numData = res.data;
        })
        .catch(res => {
          loading.close();
        });
    },
    getAdvice() {
      //获取区县中心审查意见
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      getAdvice({ projectId: this.projectId, groupId: 19, type: 0 })
        .then(res => {
          loading.close();
          if (res.data) {
            this.form1 = res.data;
          }
        })
        .catch(res => {
          loading.close();
        });
    },
    getAdvice1() {
      //获取区县中心审查意见
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      getAdvice({ projectId: this.projectId, groupId: 19, type: 1 })
        .then(res => {
          loading.close();
          if (res.data) {
            this.form = res.data;
          }
        })
        .catch(res => {
          loading.close();
        });
    },
    addAdvice() {
      //生成审查意见表
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.form.createTime = moment(this.form.createTime).format(
        "YYYY-MM-DD HH:mm:SS"
      );
      this.form.signature = this.signature;
      this.form.projectId = this.projectId;
      addAdvice(this.form)
        .then(res => {
          loading.close();
          this.$message({
            message: "提交成功！",
            type: "success"
          });
          this.getAdvice();
          this.$router.push("/projectManagement/projectImplementation/dealwith")
        })
        .catch(res => {
          loading.close();
        });
    },
    upData() {
      //添加耕地质量等别评定成果信息
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.numData.projectId = this.projectId;
      this.numData.flag = 1;
      for (const key in this.numData) {
        if (key !== "declareUnit" && key !== "operationUnit") {
          this.numData[key] = this.numData[key] * 1;
        }
      }
      addResult(this.numData)
        .then(res => {
          loading.close();
          this.getInvAndCon();
          this.addAdvice();
        })
        .catch(res => {
          loading.close();
        });
    },
    getSignature() {
      //获取用户签名
      getSignature().then(res => {
        this.signature = res.data;
      });
    }
  }
};
</script>
<style lang="scss" scoped>
.cityCheckResult {
  padding: 30px 0;
  background: #f5f6f7;
  .basicInfoForm {
    background: #fff;
    padding: 20px;
  }
  .maintitle {
    font-size: 18px;
    font-family: PingFang SC;
    font-weight: bold;
    line-height: 25px;
    color: #4d4d4d;
    margin-top: 60px;
    margin-bottom: 30px;
    &:first-child {
      margin-top: 0;
    }
  }
  .basicInfoForm {
    span {
      display: inline-block;
      margin: 20px 60px 0 0;
      font-size: 14px;
      color: #999999;
    }
    .tit {
      color: #666666;
      font-weight: bold;
      margin-right: 0;
      height: 40px;
      line-height: 40px;
      margin: 0;
    }
    .basicSituation {
      margin-top: 20px;
    }
  }
  .equalArea div .tit:nth-of-type(2n) {
    margin-left: 40px;
  }
  .formcontent {
    margin-top: 30px;
  }
  .secondtitle {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 500;
    line-height: 20px;
    margin-right: 20px;
    line-height: 38px;
  }
}
</style>